home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Text / Edit / XDme / Macros / C / func.xdme < prev    next >
Encoding:
Text File  |  1994-08-09  |  1.5 KB  |  69 lines

  1. #
  2. #   Convert a header to a function
  3. #
  4. #   $VER: hdr2func V1.01 (25.05.1993)
  5. #
  6.  
  7. # Remember position
  8. push pos
  9.  
  10. # Find RETURN. To be more save, we look for NAME first
  11. findstr NAME prev find RETURN down scanf %[~;]
  12.  
  13. # Look for the beginning of the function-body
  14. find */ find {
  15. # move to the decl. line
  16. up
  17. # clear this line
  18. if c<>32 deline insline
  19.  
  20. # insert "return"
  21. ($scanf)
  22. # check the last part. If it's not "void", remove it
  23. last wleft if x<>1 `if c<>"void" remeol'
  24.  
  25. # get name of function
  26. findstr NAME prev down scanf w
  27. # and copy it
  28. find */ find { up last right ($scanf)
  29.  
  30. # search parameters
  31. findstr PARAMETER prev down
  32. # remember old block and begin to mark new one
  33. push block block
  34. # find the column we begin in
  35. firstnb set column $colno
  36. # as long as there is no empty line, do down
  37. while x>=$column `down firstnb'
  38. # we are one line too deep now
  39. up
  40. # end block
  41. block
  42. # copy block to function-head. Remember the position of the first line of
  43. # the block
  44. find */
  45. find {
  46. push pos
  47. bcopy
  48.  
  49. # goto begining of line
  50. peek auto
  51. first
  52. # remove comments
  53. while c<>"{" (firstnb scanf %[~;] remeol first (\$scanf) down first)
  54. # go up
  55. pop auto
  56. # replace all ';' by ',' and join things together until we find a '{'
  57. while c<>"{" `last `,' join last left'
  58.  
  59. # get rid of '{' and the last ','
  60. split last bs
  61. # add a '(' after the name of the function, join the args and add a ')' at the
  62. # end
  63. up last right `(' join del last `)'
  64. # remove all obsolete blanks
  65. unjustify
  66. # pop block & position
  67. pop auto
  68. pop auto
  69.